﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/MasterNhanSuTienLuong.Master" Inherits="System.Web.Mvc.ViewPage<DTTB.MV2.QUANLYNHANSUTIENLUONG.Models.FormBean.PhanQuyen.UsersForm>" %>

<%@ Import Namespace="Webdiyer.WebControls.Mvc" %>
<%@ Import Namespace="DTTB.DTO" %>
<%--<%@ Import Namespace="FLVS.SRS.Core.Dto" %>
<%@ Import Namespace="MvcPaging" %>
<%@ Import Namespace="MvcContrib.UI.Pager" %>--%>
<%@ Import Namespace="System.Web.Mvc.Html" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">

</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">

    <script type="text/javascript" language="javascript">
        $(document).ready(function() {
            selectMenu("HeThong-Users");
             $("#HeThong-Users").parent().attr("class", "active");
            $("#tabs").tabs();
            $("#tabs").tabs('select',<%=Model.HidLastTab %>);
            
            $("#GiaTriSearch").focus();
            
             $("#arrow").click(function () {
                 $("#open_close").slideToggle("slow");
                 if ($(this).hasClass('background_arrow_down')) {
                     $(this).addClass('background_arrow_up').removeClass('background_arrow_down');
                 }
                 else {
                     $(this).addClass('background_arrow_down').removeClass('background_arrow_up');
                 }
            });
            
        });

        $(function() {
            $("#BirthDay").datepicker();
        });
        
    </script>

    <script type="text/javascript" language="javascript" src="<%= ResolveUrl("~/Content/Scripts/User/users.js") %>"></script>

    <%Html.BeginForm();%>
    <%=Html.Hidden("IsAdministrator")%>
    <%=Html.Hidden("IsActive")%>    
    <%=Html.Hidden("HidLastTab")%>
    <input type="hidden" id="ChucVuKiemString" name="ChucVuKiemString" value="<%=string.Empty %>" />
    <input type="hidden" id="UserID" name="UserID"/>
    <input type="hidden" id="UserLoginID" value="<%=Model.UserLoginID %>" name="UserID"/>
    <input type="hidden" id="Sex" value="<%=Model.Sex %>" name="Sex"/>

    <%--<div class="module">--%>
    <div class="formBox">
    <div class="box">        
		<!-- box / title -->
         <div class="breadcrumbs">
          <ul>
            <li class="home"><a href="">Quản lý hệ thống</a></li>
            <li><a href="">Quản lý Người dùng</a></li>
            <li>Page</li>
          </ul>
        </div>
           <div class="headlines">
            <h2>
                <span>Quản lý Người dùng</span>
            </h2>
               <%-- <a class="show-filter" href="#">show filter</a>--%>
        </div>
	
		<!-- end box / title -->
        <%--<div class="module_top">
        </div>--%>
        <%--<div class="contain_module">--%>
            <%
                bool isDemoProject = Convert.ToString(ConfigurationManager.AppSettings["IsDemoProject"]).ToLower() != "false";
            %>
            <div id="tabs">
                <ul>
                    <li><a href="#fragment-2"><span style="font-size: 12px; color: #666666">Tạo/Cập nhật</span></a></li>
                    <li><a href="#fragment-3"><span style="font-size: 12px; color: #666666">Thay đổi Mật khẩu</span></a></li>
                </ul>
                <div id="fragment-2">
                    <table class="table_module" style="line-height:24px">
                        <%--Thông Báo--%>
                        <%
                            if (Model.MessageCreateUser != null)
                            {
                        %>
                        <div id="MessageCreateUser" style="font-size: 12px; color: Blue; font-weight: bold">
                            <%=Model.MessageCreateUser %></div>
                        <%
                            }
                        %>
                        <%
                            if (Model.MessageEditUser != null)
                            {
                        %>
                        <div id="MessageEditUser" style="font-size: 12px; color: Blue; font-weight: bold">
                            <%=Model.MessageEditUser %></div>
                        <%
                            }
                        %>
                        <%--end--%>
                        <tr>
                            <td colspan="4" align="right" class="btn-submit">
                                <input type="button" class="button" value="Tạo/Cập nhật" onclick="DoCreateOrEdit()" />
                                <input type="button" class="button" value="Tạo mới" onclick="javascript:DoNew();" />
                                <input type="button" class="button" value="Xóa" onclick="javascript:DoDelete();" id="btnDelete1" />
                                <input type="button" class="button" value="Nhập lại" onclick="javascript:DoReset();" />
                            </td>
                        </tr>
                        <tr>
                            <td><%--Mã người dùng :--%>&nbsp;</td>
                            <td colspan="3">
                                <%--<input type="text" name="ID" id="ID" disabled="disabled" value='<%=Model.ID %>' size="30" />--%>
                                <input type="hidden" name="ID" id="ID" value='<%=Model.ID %>' />
                            </td>
                        </tr>
                        <tr>
                            <td style="width: 15%"><b>Tên đăng nhập:</b></td>
                            <td style="width: 42%">
                                <input size="30" type="text"  value="<%=Model.UserName%>" id="UserName" name="UserName" onblur="javascript:doCheckUsernameIsExist();" tabindex="1"
                                    <%if(Model.UserNameReadOnly)
                                    {%> disabled="disabled" <%}%> />
                                <div id="IsExistUserName" style="color: Red">
                                </div>
                            </td>
                             <td nowrap="nowrap">Giới tính:</td>
                            <td>
                                <input type="radio" value="1" id="Nam" name="GioiTinh" <%if(Model.Sex){%>checked="checked"<%} %> tabindex="7"/>Nam &nbsp;&nbsp;
                                <input type="radio" value="0" id="Nu"name="GioiTinh" <%if(Model.Sex == false){%>checked="checked"<%} %> tabindex="8"/>Nữ
                            </td>
                        </tr>
                        <tr>
                            <td><b>Mật khẩu:</b></td>
                            <td>
                                <input type="password" size="30" id="Password" value="<%=Model.Password%>" onblur="javascript:doCheckPassword();" tabindex="2"
                                    <%if(Model.PasswordReadOnly)
                                    {%> disabled="disabled" <%}%>  name="Password" />
                                <div id="PasswordMessage" style="color: Red">
                                </div>
                            </td>
                            <td nowrap="nowrap">Ngày sinh:</td>
                            <td>
                                <input type="text" id="BirthDay" name="BirthDay" size="30" value="<%= Model.BirthDay.ToString() == DateTime.MinValue.ToString() ? string.Empty : Model.BirthDay.ToString("MM/dd/yyyy") %>" tabindex="9"/>
                            </td>
                        </tr>
                        <tr>
                            <td><b>Nhập lại Mật khẩu:</b></td>
                            <td>
                                <input type="password" size="30" id="RePassword" value='<%=Model.Password%>' onblur="javascript:doCheckRetypePassword();" tabindex="3"
                                    <%if(Model.PasswordReadOnly)
                                {%> disabled="disabled" <%}%> name="RePassword" />
                                <div id="RePasswordMessage" style="color: Red">
                                </div>
                            </td>
                            <td>Điện thoại :</td>
                            <td colspan="3">
                                <input type="text" name="Mobile" id="Mobile" value='<%= Model.Mobile %>' size="30" tabindex="10"/> 
                            </td>                            
                        </tr>
                        <tr>
                            <td>Họ tên:</td>
                            <td>
                                <input type="text" name="FullName" id="FullName" size="30" value="<%=Model.FullName%>" tabindex="4"/>
                            </td>
                            <td>Email:</td>
                            <td>
                                <input type="text" id="Email" name="Email" size="30" value="<%=Model.Email %>" onblur="javascript:doCheckEmail();" tabindex="11"/>
                                <div id="EmailMessage" style="color: Red">
                                </div>
                            </td>                           
                        </tr>
                        <tr>
                            <td>Phòng ban:</td>
                            <td>
                                <%=Html.DropDownList("Department", Model.DepartmentsSelectList, new { @style = "width:230px;", @tabindex = "5" })%>
                                <div id="DepartmentMessage" style="color: Red">
                                </div>
                            </td>
                            <td nowrap="nowrap">Tài khoản Quản trị :</td>
                            <td>
                                
                                <input type="checkbox" <%if(Model.IsAdministrator){%> checked="checked" <%}%> <%if(isDemoProject){%> disabled="disabled"<%}%>  id="IsAdministratorBox" name="IsAdministratorBox" tabindex="12"/>
                            </td>
                        </tr>
                        <tr>
                            <td>Chức vụ :</td>
                            <td>
                                <%=Html.DropDownList("JobTitle", Model.JobTitlesSelectList, new { @style = "width:230px", @tabindex = "6" })%>
                                <div id="JobTitleMessage" style="color: Red">
                                </div>
                            </td>    
                            <td nowrap="nowrap">Kích hoạt Tài khoản:</td>
                            <td>
                                <input type="checkbox" <%if(Model.IsActive){%> checked="checked" <%}%><%if(isDemoProject){%> disabled="disabled"<%}%> id="IsActiveBox" name="IsActiveBox" tabindex="13"/>
                            </td>
                        </tr>
                        <tr style="line-height:20px"><td colspan="4">&nbsp;</td></tr>
                        <tr>
                            <td colspan="4">
                                <p style="margin:0px 0px 10px 40px"><b>Các chức vụ Nhân viên đang kiêm &nbsp;</b></p>
                                <div id="arrow" class="background_arrow_down" style="float: left; cursor: pointer;
                                    clear: both; margin-top: -20px;">
                                </div>
                                <div id="open_close" class="bo" style="width: 100%; border: 1px solid #999;
                                    line-height: 25px; margin-left: 0%; margin-bottom: 15px;">
                                    
                                    <table width="100%">
                                    <%
                                    for (int i = 0 ; i< Model.JobTitlesList.Count; i++)
                                    {
                                    %>
                                        <%if(i % 3 == 0)
                                        {
                                        %>
                                            <tr>
                                        <%
                                        }
                                        %>

                                        <%
                                        
                                        //xử lý check cho Checkbox là chức vụ kiêm của nhân viên hiện hành
                                        bool isChecked = false;
                                        
                                        if (Model.UserInJobTitleInDepartmentList.Count != 0 && Model.UserInJobTitleInDepartmentList.Any(userInJobTitleInDepartmentDto =>
                                                Model.JobTitlesList[i].ID == userInJobTitleInDepartmentDto.JobTitleId))
                                        {
                                            isChecked = true;
                                        } 
                                        //end xử lý check
                                        
                                        %>

                                        
                                        <td style="width:5%; text-align:right">
                                            <input type="checkbox" id="<%=Model.JobTitlesList[i].ID %>" name="chucvukiem" <%if(isChecked){%> checked="checked" <%}%> />&nbsp;
                                        </td>
                                        <td style="width:28%">
                                            <%=Model.JobTitlesList[i].JobTitle %>
                                        </td>

                                        <%
                                        if(i%3 == 2)
                                        {
                                        %>
                                            </tr>
                                        <%
                                        }
                                        %>                                  
                                    <%
                                    }     
                                    %>
                                    </table>

                                </div>
                            </td>
                        </tr>
                        <tr>
                            <td colspan="4" align="right" class="btn-submit">
                                <input type="button"class="button" value="Tạo/Cập nhật" onclick="DoCreateOrEdit()" />
                                <input type="button"class="button"value="Tạo mới" onclick="javascript:DoNew();" />
                                <input type="button"class="button" value="Xóa" onclick="javascript:DoDelete();" id="btnDelete2" />
                                <input type="button"class="button" value="Nhập lại" onclick="javascript:DoReset();" />
                            </td>
                        </tr>
                    </table>
                </div>
                <%--Reset Pass--%>
                <div id="fragment-3">
                    <table class="table_module" style="line-height:24px" width="100%">
                        <%--Thông Báo--%>
                        <%
                            if (Model.MessageChangePassword != null)
                            {
                        %>
                        <div id="MessageChangePassword" style="font-size: 12px; color: Blue; font-weight: bold">
                            <%=Model.MessageChangePassword %></div>
                        <%
                            }
                        %>
                        <%--end--%>
                        <input type="hidden" id="ErrorChangePassword" name="ErrorChangePassword" value="Model.ErrorChangePassword" />
                        <br />
                        <tr>
                            <td>
                                Ngừơi dùng:
                            </td>
                            <td colspan="2">
                                <input type="text" style="color: Blue" disabled="disabled" size="33" value="<%= Model.UserName %>" id="UserNameForResetPassword" name="UserNameForResetPassword" />
                            </td>
                        </tr>
                        <tr>
                            <td width="25%">
                                Mật khẩu mới:
                            </td>
                            <td width="35%">
                                <%=Html.TextBox("PasswordChange", Model.PasswordChange, new { @size = 33, @onkeypress = "if (event.keyCode==13) { return doResetPassword(); }", @type = "password", @onblur = "javascript:doOnBlurPasswordChange();" })%>&nbsp;
                            </td>
                            <td>
                                <div id="PasswordChangeMessage" style="color: Red">
                                </div>
                            </td>
                        </tr>
                        <tr>
                            <td>
                               Nhập lại Mật khẩu mới:
                            </td>
                            <td>
                                <%=Html.TextBox("RePasswordChange", Model.RePasswordChange, new { @size = 33, @onkeypress = "if (event.keyCode==13) { return doResetPassword(); }", @type = "password", @onblur = "javascript:doOnBlurRePasswordChange();" })%>&nbsp;
                            </td>
                            <td>
                                <div id="RePasswordChangeMessage" style="color: Red">
                                </div>
                            </td>
                        </tr>
                        <tr>
                            <td>
                                &nbsp;
                            </td>
                            <td align="left" class="btn-submit">
                            <%
                            if(isDemoProject == false)
                            {
                            %>
                            <input type="button" value="Reset" class="button" onclick="javascript:doResetPassword();" />
                            <%
                            }
                            else
                            {
                            %>
                            <input type="button" value="Reset" class="button" onclick="javascript:doResetPasswordDemoProject();" />
                            <%
                            }
                            %>
                                
                            </td>
                        </tr>
                    </table>
                </div>
            </div>
            <div class="pagebreak"> &nbsp;</div>
            <table class="table_outsite" width="100%">
                <tr>
                    <td colspan="2" class="first">
                        &nbsp;<b>Danh sách Nhân viên:</b>
                    </td>
                    <td colspan="2" class="first" align="right">
                        <%=Html.DropDownList("TieuChiSearch", Model.TieuChiSearchDropDownList)%>
                        <%=Html.TextBox("GiaTriSearch", Model.GiaTriSearch, new { @onkeypress = "if (event.keyCode==13) { return DoSearch(); }", Style = "width:210px" })%>
                        <img onclick="javascript:DoSearch();" style="vertical-align: middle; cursor:pointer" src="<%=ResolveUrl("~/Content/ImagesAdmin/search_icon.gif")%>"
                            alt="Tìm nhân viên" title="Tìm nhân viên"/>
                    </td>
                </tr>
                <tr>
                    <td colspan="4">
                        <table cellspacing="0" cellpadding="0"  class="tab tab-drag">
                            <tr class="top nodrop nodrag" style="font-weight: bold">
                                <td width="5%" class="first"  align="center">
                                    <strong>STT</strong>
                                </td>
                                <td align="left" nowrap="nowrap">
                                    <strong><a href="javascript:doSort('Fullname');" >Tên nhân viên</a></strong>
                                </td>
                                <td align="left"  nowrap="nowrap">
                                    <strong><a href="javascript:doSort('Username');" >Tên đăng nhập</a></strong>
                                </td>
                                <td width="7%">
                                   <strong><a href="javascript:doSort('Status');" >Trạng thái</a></strong>
                                </td>
                                <td align="center">
                                    <strong>Role</strong>
                                </td>
                                <td align="center" nowrap="nowrap">
                                   <strong>Permission</strong>
                                </td>
                                <td width="11%" align="left" nowrap="nowrap">
                                    <strong>Ngày cập nhật</strong>
                                </td>
                                <td align="left" class="last" nowrap="nowrap"><%--class="last"--%>
                                   <strong>Người cập nhật</strong>
                                </td>
                            </tr>
                            <%--Users List--%>
                            <%
                            IList<UsersDto> usersDtoList = Model.UsersPagedList;
                            int dem = 0;
                            foreach (UsersDto dto in usersDtoList)
                            {
                            %>
                            <tr class="item_row" onclick="javascript:highlight(this);EditUsers(<%=dto.ID%>);">
                                <td class="first" align="center">
                                   <%=++dem%>
                                </td>
                                <td align="left" nowrap="nowrap">
                                    &nbsp;<%=dto.FullName%>
                                </td>
                                <td align="left">
                                    &nbsp;<b><%=dto.UserName%></b>
                                </td>
                                <td nowrap="nowrap">&nbsp;
                                    <%
                                        if (dto.IsActive)
                                        {%>
                                   <span style="color:blue"> Đang hoạt động</span>
                                    <%}
                                            else
                                            {%>
                                    <span style="color:red">Đang khóa</span>
                                    <%}%>
                                </td>
                                <td align="center">&nbsp;
                                    <%if (dto.RoleExist)
                                      {%>
                                    Yes
                                    <%}
                                      else
                                      {%>
                                    No
                                    <%}%>
                                </td>
                                <td align="center">&nbsp;
                                    <%if (dto.SpecialPermission)
                                      {%>
                                    Yes
                                    <%}
                                      else
                                      {%>
                                    No
                                    <%}%>
                                </td>
                                <td align="left">&nbsp;
                                    <%=dto.UpdateDate.ToString("dd/MM/yyyy")%>
                                </td>
                                <td class="last" nowrap="nowrap">
                                    &nbsp;<%=dto.UpdateByUser%>
                                </td>
                            </tr>
                            <%}
                            %>
                            <tr class="border_bottom">
                                <td class="first" style="background: #DDDDDD">
                                </td>
                                <td class="last" colspan="7" align="right" style="background: #DDDDDD; padding-right: 10px">
                                    <div><%=Html.Pager(Model.UsersPagedList,new PagerOptions{PageIndexParameterName="id"}) %></div>
                                </td>
                            </tr>
                            <%--dã xóa--%>
                        </table>
                    </td>
                </tr>
            </table>
            
       <%-- </div>--%>
    </div>
    </div>
    <%Html.EndForm(); %>
</asp:Content>
